package com.pass.util;

import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;

import androidx.annotation.NonNull;

/**
 * @ClassName AlbumUtil
 * @Description 相册工具类
 * @Author guchu
 * @Date 2021/1/3 17:52
 * @Version 1.0
 */
public class AlbumUtil {
    /**
     * 从相册选择一张图片(这里是原图)
     *
     * @param activity
     * @param requestCode onActivityResult成功后
     *                    Uri uri = data.getData();
     *                    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
     *                    if (cursor != null && cursor.moveToFirst()) {
     *                    String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
     *                    if (mBitmap != null) {
     *                    mBitmap.recycle();
     *                    }
     *                    int rotatedDegree = BitmapUtil.getRotatedDegree(path);
     *                    Bitmap rawBitmap = BitmapFactory.decodeFile(path);
     *                    mBitmap = BitmapUtil.rotateBitmap(rawBitmap, rotatedDegree, false);
     *                    mImageView.setImageBitmap(mBitmap);
     *                    }
     */
    public static void getBitmap(@NonNull Activity activity, int requestCode) {
        Intent intentToPickPic = new Intent(Intent.ACTION_PICK, null);
        intentToPickPic.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        activity.startActivityForResult(intentToPickPic, requestCode);
    }
}
